﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections.Generic;
using System.IO;

using CE.User;
using CE.Global;
using CE.Database;
using CE.CarInsurance;
using CE.PersonalAccident;

public partial class carinsurance_RetrieveCIQuotes : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/SiteUserSecureLogin.aspx");
        }

        if (!IsPostBack)
        {
            LoadCoverType();
            LoadBrokerProvider();
            LoadBrokerCoverType();
            EnableCustomerMoreDetail(false);
            divCXBrokerPremium.Visible = false;
            divBrokerCallStatus.Visible = false;
            txtAgentId.Text = Session[General.UserId].ToString();            
        }
    }

    protected void grvCarInsurance_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (grvCarInsurance.Rows.Count > 0 && grvCarInsurance.SelectedIndex >= 0)
        {
            ClaerMore();
            hplDownLoad.Visible = false;
            divCXBrokerPremium.Visible = true;
            divBrokerCallStatus.Visible = true;
            DataKey myData = grvCarInsurance.SelectedDataKey;
            txtCustomerId.Text = myData[0].ToString();
            txtCarId.Text = myData[1].ToString();
            txtCarPolicyId.Text = myData[2].ToString();
            txtContactNo.Text = myData[3].ToString();
            txtCIRemark.Visible = false;
            txtPARemark.Visible = false;

            grvPremiumList.DataBind();
            if (grvPremiumList.Rows.Count > 0)
            {
                divPremiumList.Visible = true;
                hplPremiumDownLoad.Visible = true;
                hplPremiumDownLoad.NavigateUrl = PremiumDownloadURL();
            }
            else
            {
                divPremiumList.Visible = false;
                hplPremiumDownLoad.Visible = false;
                hplPremiumDownLoad.NavigateUrl = "";
            }

            txtServerPath.Text = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CIProposalServerPath");
            grvCarInsuranceCheapestQuote.DataBind();
            if (grvCarInsuranceCheapestQuote.Rows.Count > 0)
            {
                grvCarInsuranceCheapestQuote.Sort("AnnualPremium", SortDirection.Ascending);
                grvCarInsuranceCheapestQuote.SelectedIndex = 0;
                txtCarResultId.Text = "0";
                txtCXCRMId.Text = "0";
                txtCIRemark.Text = "";
                txtPARemark.Text = "";
                lblCallStatusMessage.Text = "";
                ddlCallFor.Text = "-1";
                ddlCICallStatus.Text = "-1";
                ddlPACallStatus.Text = "-1";
                txtCallStatusId.Text = "0";
                if (txtCustomerId.Text != string.Empty && txtCarId.Text != string.Empty)
                {
                    MyDatabase _db = new MyDatabase();

                    DataTable _dtSelect = new DataTable("dtSelect");
                    bool _IsAddDriver = false;
                    string _strSelect = "SELECT IsAddDriver, NoOfDriver FROM tblCarPolicy"
                        + " WHERE RefCEUserId = " + txtCustomerId.Text + " AND CECarId= " + txtCarId.Text;
                    _dtSelect = _db.GetDataTable(_strSelect);
                    if (_dtSelect != null && _dtSelect.Rows.Count > 0)
                    {
                        _IsAddDriver = Convert.ToBoolean(_dtSelect.Rows[0]["IsAddDriver"].ToString());
                        if (_IsAddDriver == true)
                        {
                            txtNoofDriver.Text = _dtSelect.Rows[0]["NoOfDriver"].ToString();
                        }
                        else
                        {
                            txtNoofDriver.Text = "0";
                        }
                    }

                    _dtSelect = null;
                    _dtSelect = new DataTable("dtSelect");

                    int _DriverCount = Convert.ToInt32(txtNoofDriver.Text);
                    if (_DriverCount > 0)
                    {
                        _strSelect = "SELECT CarDriverId, CONVERT(VARCHAR,DOB,106) AS DOB,DriverGender = CASE WHEN Gender = 'M' THEN 'Male' ";
                        _strSelect += " WHEN Gender = 'F' THEN 'Female' END FROM tblCarDriver WHERE [Status] = 'Active' ";
                        _strSelect += " AND CECarId = " + txtCarId.Text;
                        _strSelect += " AND RefCEUserId = " + txtCustomerId.Text;
                        _dtSelect = _db.GetDataTable(_strSelect);
                        if (_dtSelect != null && _dtSelect.Rows.Count > 0)
                        {
                            if (_dtSelect.Rows.Count > 0)
                            {
                                txtDriverId1.Text = _dtSelect.Rows[0]["CarDriverId"].ToString();
                                string driverDOB1 = _dtSelect.Rows[0]["DOB"].ToString();
                                string driverGender1 = _dtSelect.Rows[0]["DriverGender"].ToString();
                                lblDriverDOB1.Text = "1st Driver  DOB :  " + driverDOB1 + "    Gender :  " + driverGender1;
                            }
                            if (_dtSelect.Rows.Count > 1)
                            {
                                txtDriverId2.Text = _dtSelect.Rows[1]["CarDriverId"].ToString();
                                string driverDOB2 = _dtSelect.Rows[1]["DOB"].ToString();
                                string driverGender2 = _dtSelect.Rows[1]["DriverGender"].ToString();
                                lblDriverDOB2.Text = "2nd Driver  DOB :  " + driverDOB2 + "    Gender :  " + driverGender2;
                            }
                            if (_dtSelect.Rows.Count > 2)
                            {
                                txtDriverId3.Text = _dtSelect.Rows[2]["CarDriverId"].ToString();
                                string driverDOB3 = _dtSelect.Rows[2]["DOB"].ToString();
                                string driverGender3 = _dtSelect.Rows[2]["DriverGender"].ToString();
                                lblDriverDOB3.Text = "3rd Driver  DOB :  " + driverDOB3 + "    Gender :  " + driverGender3;
                            }
                            if (_dtSelect.Rows.Count > 3)
                            {
                                txtDriverId4.Text = _dtSelect.Rows[3]["CarDriverId"].ToString();
                                string driverDOB4 = _dtSelect.Rows[3]["DOB"].ToString();
                                string driverGender4 = _dtSelect.Rows[3]["DriverGender"].ToString();
                                lblDriverDOB4.Text = "4th Driver  DOB :  " + driverDOB4 + "    Gender :  " + driverGender4;
                            }
                            if (_dtSelect.Rows.Count > 4)
                            {
                                txtDriverId5.Text = _dtSelect.Rows[4]["CarDriverId"].ToString();
                                string driverDOB5 = _dtSelect.Rows[4]["DOB"].ToString();
                                string driverGender5 = _dtSelect.Rows[4]["DriverGender"].ToString();
                                lblDriverDOB5.Text = "5th Driver  DOB :  " + driverDOB5 + "    Gender :  " + driverGender5;
                            }
                        }
                        _dtSelect = null;
                        _dtSelect = new DataTable("dtSelect");
                    }
                    _strSelect = "SELECT COUNT(*) AS TotalRecord FROM tblCXCarMoreDetail WHERE CECarId = " + txtCarId.Text;
                    _strSelect += " AND RefCEUserId = " + txtCustomerId.Text;
                    _dtSelect = _db.GetDataTable(_strSelect);
                    if (_dtSelect != null && _dtSelect.Rows.Count > 0)
                    {
                        Int64 _Count = Convert.ToInt64(_dtSelect.Rows[0]["TotalRecord"].ToString());
                        if (_Count > 0)
                        {
                            divCustomerMoreDetail.Visible = false;
                            hplDownLoad.Visible = true;
                            EnableCustomerMoreDetail(false);
                            btnSubmitPremium.Enabled = true;
                            hplDownLoad.NavigateUrl = "~/CarInsurance/QuoteDownload.aspx?carid=" + txtCarId.Text + "&userid=" + txtCustomerId.Text;
                        }
                        else
                        {
                            divCustomerMoreDetail.Visible = true;
                            hplDownLoad.Visible = false;
                            EnableCustomerMoreDetail(true);
                            btnSubmitPremium.Enabled = false;
                        }
                    }
                    else
                    {
                        divCustomerMoreDetail.Visible = false;
                        hplDownLoad.Visible = false;
                        EnableCustomerMoreDetail(false);
                        btnSubmitPremium.Enabled = false;
                    }
                    _db = null;
                    _dtSelect = null;
                    divCallStatus.Visible = true;
                    Int32 CallTypeId = 100;
                    CallStatus CI_callstatus = new CallStatus();
                    CallStatusDB CI_callstatusdb = new CallStatusDB();
                    CI_callstatus = CI_callstatusdb.GetCallStatus(Convert.ToInt64(txtCarId.Text), Convert.ToInt64(txtCustomerId.Text), CallTypeId);

                    if (CI_callstatus != null)
                    {
                        ddlCallFor.Text = "100";
                        txtCXCRMId.Text = CI_callstatus.CXCRMId.ToString();
                        ddlCICallStatus.Text = CI_callstatus.AgentCallStatus.ToString();
                        txtCIRemark.Text = Server.HtmlDecode(CI_callstatus.Remark);
                        txtCIRemark.Visible = true;
                        ddlCallFor_SelectedIndexChanged(null, null);
                    }
                    else
                    {
                        txtCXCRMId.Text = "0";
                    }

                    PACallStatus PA_callstatus = new PACallStatus();
                    PACallStatusDB PA_callstatusdb = new PACallStatusDB();
                    PA_callstatus = PA_callstatusdb.GetCallStatus(Convert.ToInt64(txtCarId.Text), Convert.ToInt64(txtCustomerId.Text));

                    if (PA_callstatus != null)
                    {
                        ddlPACallStatus.Text = PA_callstatus.AgentCallStatus.ToString();
                        txtCallStatusId.Text = PA_callstatus.CallStatusId.ToString();
                        txtPARemark.Text = Server.HtmlDecode(PA_callstatus.Remark);
                        if (CI_callstatus == null)
                        {
                            ddlCallFor.Text = "200";
                            ddlCallFor_SelectedIndexChanged(null, null);
                        }
                    }
                    else
                    {
                        txtCallStatusId.Text = "0";
                    }

                    //Sakthi on 07 Jan 2011 -- Start
                    DataSet _dsCallStatus = CI_callstatusdb.GetCallStatusDS(Convert.ToInt64(txtCarId.Text), Convert.ToInt64(txtCustomerId.Text), 101, 0);
                    if (_dsCallStatus != null && _dsCallStatus.Tables.Count > 0)
                    {
                        if (_dsCallStatus.Tables[0].Rows.Count > 0)
                        {
                            pnlCallStatus.Visible = true;
                            txtCallStatus.Text = Server.HtmlDecode(_dsCallStatus.Tables[0].Rows[0]["Remark"].ToString());
                        }
                        else
                        {
                            pnlCallStatus.Visible = false;
                        }
                    }
                    else
                    {
                        pnlCallStatus.Visible = false;
                    }
                    //Sakthi on 07 Jan 2011 -- End
                    CI_callstatus = null;
                    CI_callstatusdb = null;

                    PA_callstatus = null;
                    PA_callstatusdb = null;
                }
                else
                {
                    divCustomerMoreDetail.Visible = false;
                    hplDownLoad.Visible = false;
                }
            }
            //Broker Call Status

            lblPremiumError.Text = "";
            lblPremiumMessage.Text = "";
            ddlBrokerProvider.SelectedIndex = 0;
            ddlBrokerCoverType.SelectedIndex = 0;
            txtPremiumId.Text = "0";
            txtPremium.Text = "";
            txtExcess.Text = "";
            txtPremiumPackage.Text = "";
            txtWorkShop.Text = "";
            chkSelected.Checked = false;

            txtBrokerCallStatusId.Text = "0";
            txtBrokerRemark.Text = "";
            lblBrokerCallStatusMessage.Text = "";
            ddlBrokerCallStatus.Text = "-1";
            if (txtCustomerId.Text != string.Empty && txtCarId.Text != string.Empty)
            {

                Int32 CallTypeId = 192;
                BrokerCallStatus _brokercallstatus = new BrokerCallStatus();
                BrokerCallStatusDB _brokercallstatusdb = new BrokerCallStatusDB();
                _brokercallstatus = _brokercallstatusdb.GetCallStatus(Convert.ToInt64(txtCarId.Text), Convert.ToInt64(txtCustomerId.Text), CallTypeId);

                if (_brokercallstatus != null)
                {
                    txtBrokerCallStatusId.Text = _brokercallstatus.CallStatusId.ToString();
                    ddlBrokerCallStatus.Text = _brokercallstatus.AgentCallStatus.ToString();
                    txtBrokerRemark.Text = Server.HtmlDecode(_brokercallstatus.Remark);
                }
                else
                {
                    txtBrokerCallStatusId.Text = "0";
                }
                _brokercallstatus = null;
                _brokercallstatusdb = null;
            }
        }
        else
        {
            EnableCustomerMoreDetail(false);
            divCXBrokerPremium.Visible = false;
            divBrokerCallStatus.Visible = false;
            divPremiumList.Visible = false;
            hplDownLoad.Visible = false;
            hplPremiumDownLoad.Visible = false;
            hplDownLoad.NavigateUrl = "";
            hplPremiumDownLoad.NavigateUrl = "";
        }
    }

    public void LoadLiberty()
    {
        //CarInsuranceDB _carinsurancedb = new CarInsuranceDB();

        //grvLiberty.DataSource = _carinsurancedb.GetCarInsuranceItemList(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()));
        //grvLiberty.DataBind();

    }

    private void ClaerMore()
    {
        txtLicensePassDate.Text = "";
        txtVehicleNumber.Text = "";
        txtRegistrationDate.Text = "";
        ddlCoverType.SelectedIndex = 0;
        txtNRIC.Text = "";
        ddlSuspensionDrivingLicense.SelectedIndex = 0;
        ddlPolicyCancelled.SelectedIndex = 0;

        txtDriverId1.Text = "0";
        txtDriverId2.Text = "0";
        txtDriverId2.Text = "0";
        txtDriverId3.Text = "0";
        txtDriverId5.Text = "0";
        txtDriverName1.Text = "";
        txtDriverName2.Text = "";
        txtDriverName3.Text = "";
        txtDriverName4.Text = "";
        txtDriverName5.Text = "";
        txtDriverLicensePassDate1.Text = "";
        txtDriverLicensePassDate2.Text = "";
        txtDriverLicensePassDate3.Text = "";
        txtDriverLicensePassDate4.Text = "";
        txtDriverLicensePassDate5.Text = "";
        txtDriverNRIC1.Text = "";
        txtDriverNRIC2.Text = "";
        txtDriverNRIC3.Text = "";
        txtDriverNRIC4.Text = "";
        txtDriverNRIC5.Text = "";
        txtDriverRelation1.Text = "";
        txtDriverRelation2.Text = "";
        txtDriverRelation3.Text = "";
        txtDriverRelation4.Text = "";
        txtDriverRelation5.Text = "";

    }

    protected void ibtSubmit_Click(object sender, EventArgs e)
    {
        EnableCustomerMoreDetail(false);
        divCXBrokerPremium.Visible = false;
        divBrokerCallStatus.Visible = false;
        divPremiumList.Visible = false;
        hplDownLoad.Visible = false;
        hplPremiumDownLoad.Visible = false;
        hplDownLoad.NavigateUrl = "";
        hplPremiumDownLoad.NavigateUrl = "";

        txtCallStatusId.Text = "";
        txtCarId.Text = "";
        txtCustomerId.Text = "";
        txtCarPolicyId.Text = "";
        txtCIRemark.Text = "";
        txtPARemark.Text = "";

        grvCarInsurance.DataBind();
        grvCarInsuranceCheapestQuote.DataBind();

        lblCallStatusMessage.Text = "";
        divCallStatus.Visible = false;
        divCustomerMoreDetail.Visible = false;
    }

    protected void btnCallStatus_Click(object sender, EventArgs e)
    {
        lblCallStatusMessage.Text = "";
        Page.Validate();
        if (Page.IsValid)
        {
            if (txtCarId.Text.Length > 0 && txtCustomerId.Text.Length > 0)
            {
                if (ddlCallFor.Text == "100")
                {
                    CallStatus callstatus = new CallStatus();
                    CallStatusDB callstatusdb = new CallStatusDB();
                    if (txtCXCRMId.Text.Length > 0 && txtCXCRMId.Text != "0")
                    {
                        callstatus.CXCRMId = Convert.ToInt64(txtCXCRMId.Text);
                    }
                    else
                    {
                        callstatus.CXCRMId = 0;
                    }
                    callstatus.CarId = Convert.ToInt64(txtCarId.Text);
                    callstatus.CustomerId = Convert.ToInt64(txtCustomerId.Text);
                    callstatus.AgentId = Convert.ToInt64(txtAgentId.Text);
                    callstatus.AgentCallStatus = Convert.ToInt32(ddlCICallStatus.Text);
                    callstatus.CallTypeId = 100;
                    callstatus.Remark = Server.HtmlEncode(txtCIRemark.Text);
                    callstatus.CXCRMId = callstatusdb.Insert(callstatus);
                    if (callstatus.CXCRMId > 0)
                    {
                        if (txtCXCRMId.Text.Length > 0 && txtCXCRMId.Text != "0")
                        {
                            lblCallStatusMessage.Text = "UPDATE";
                        }
                        else
                        {
                            txtCXCRMId.Text = callstatus.CXCRMId.ToString();
                            lblCallStatusMessage.Text = "SUCCESS";
                        }
                    }
                    else
                    {
                        lblCallStatusMessage.Text = "FAIL";
                    }
                    callstatus = null;
                    callstatusdb = null;
                }
                else if (ddlCallFor.Text == "200")
                {
                    PACallStatus callstatus = new PACallStatus();
                    PACallStatusDB callstatusdb = new PACallStatusDB();
                    if (txtCallStatusId.Text.Length > 0 && txtCallStatusId.Text != "0")
                    {
                        callstatus.CallStatusId = Convert.ToInt64(txtCallStatusId.Text);
                    }
                    else
                    {
                        callstatus.CallStatusId = 0;
                    }
                    callstatus.CarId = Convert.ToInt64(txtCarId.Text);
                    callstatus.CIProviderCompanyId = 0;
                    callstatus.CustomerId = Convert.ToInt64(txtCustomerId.Text);
                    callstatus.ContactNo = txtContactNo.Text;
                    callstatus.CIQuoteRefNo = "CI-NORMAL";//txtCIQuoteRefNo.Text;
                    callstatus.CallTypeId = 200;
                    callstatus.AgentId = Convert.ToInt64(txtAgentId.Text);
                    callstatus.AgentCallStatus = Convert.ToInt32(ddlPACallStatus.Text);
                    callstatus.Remark = Server.HtmlEncode(txtPARemark.Text);
                    callstatus.CallStatusId = callstatusdb.Insert(callstatus);
                    if (callstatus.CallStatusId > 0)
                    {
                        if (txtCallStatusId.Text.Length > 0 && txtCallStatusId.Text != "0")
                        {
                            lblCallStatusMessage.Text = "UPDATE";
                        }
                        else
                        {
                            txtCallStatusId.Text = callstatus.CallStatusId.ToString();
                            lblCallStatusMessage.Text = "SUCCESS";
                        }
                    }
                    else
                    {
                        lblCallStatusMessage.Text = "FAIL";
                    }
                    callstatus = null;
                    callstatusdb = null;
                }
                else
                {
                    lblCallStatusMessage.Text = "FAIL";
                }
            }
            else
            {
                lblCallStatusMessage.Text = "FAIL";
            }
        }
    }

    protected void grvCarInsurance_PageIndexChanged(object sender, EventArgs e)
    {
        txtCustomerId.Text = string.Empty;
        txtCarId.Text = string.Empty;
        divCallStatus.Visible = false;
        divCustomerMoreDetail.Visible = false;
        grvCarInsurance.SelectedIndex = -1;
        grvCarInsuranceCheapestQuote.DataBind();
    }

    protected void ddlCXAgents_SelectedIndexChanged(object sender, EventArgs e)
    {
        EnableCustomerMoreDetail(false);
        divCXBrokerPremium.Visible = false;
        divBrokerCallStatus.Visible = false;
        divPremiumList.Visible = false;
        hplDownLoad.Visible = false;
        hplPremiumDownLoad.Visible = false;
        hplDownLoad.NavigateUrl = "";
        hplPremiumDownLoad.NavigateUrl = "";
        ibtSubmit_Click(sender, e);
    }

    protected void ddlQuoteDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        EnableCustomerMoreDetail(false);
        divCXBrokerPremium.Visible = false;
        divBrokerCallStatus.Visible = false;
        divPremiumList.Visible = false;
        hplDownLoad.Visible = false;
        hplPremiumDownLoad.Visible = false;
        hplDownLoad.NavigateUrl = "";
        hplPremiumDownLoad.NavigateUrl = "";
        ibtSubmit_Click(sender, e);
    }

    protected void ddlCallFor_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnCallStatus.Enabled = true;
        lblCallStatusMessage.Text = "";
        ddlCICallStatus.Enabled = true;
        ddlPACallStatus.Enabled = true;
        txtCIRemark.Enabled = true;
        txtPARemark.Enabled = true;
        btnCallStatus.Enabled = true;
        if (grvCarInsurance.Rows.Count > 0 && grvCarInsurance.SelectedIndex >= 0)
        {
            if (ddlCallFor.Text == "200")
            {

                ddlCICallStatus.Visible = false;
                rfvCICallStatus.Enabled = false;

                ddlPACallStatus.Visible = true;
                rfvPACallStatus.Enabled = true;

                txtCIRemark.Visible = false;
                txtPARemark.Visible = true;
            }
            else if (ddlCallFor.Text == "100")
            {
                ddlCICallStatus.Visible = true;
                rfvCICallStatus.Enabled = true;

                ddlPACallStatus.Visible = false;
                rfvPACallStatus.Enabled = false;

                txtCIRemark.Visible = true;
                txtPARemark.Visible = false;
            }
            else
            {
                ddlCICallStatus.Enabled = false;
                ddlPACallStatus.Enabled = false;
                txtCIRemark.Enabled = false;
                txtPARemark.Enabled = false;
                btnCallStatus.Enabled = false;
            }
        }
    }

    protected void grvCarInsuranceCheapestQuote_RowCreated(object sender, GridViewRowEventArgs e)
    {

    }

    protected void grvCarInsuranceCheapestQuote_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }

    private void EnableCustomerMoreDetail(bool OnOff)
    {
        int NoofDriver = Convert.ToInt32(txtNoofDriver.Text);
        if (NoofDriver > 0)
        {
            pnlDrivers.Visible = true;
        }
        else
        {
            pnlDrivers.Visible = false;
        }
        rfvLicensePassDate.Enabled = OnOff;
        rfvRegistrationDate.Enabled = OnOff;
        rfvVehicleNumber.Enabled = OnOff;
        rfvCoverType.Enabled = OnOff;
        rfvNRIC.Enabled = OnOff;
        rfvSuspensionDrivingLicense.Enabled = OnOff;
        rfvPolicyCancelled.Enabled = OnOff;
        pnlDriver1.Visible = false;
        pnlDriver2.Visible = false;
        pnlDriver3.Visible = false;
        pnlDriver4.Visible = false;
        pnlDriver5.Visible = false;
        rfvDriverName1.Enabled = false;
        rfvDriverNRIC1.Enabled = false;
        rfvDriverLicensePassDate1.Enabled = false;
        rfvDriverRelation1.Enabled = false;
        rfvDriverName2.Enabled = false;
        rfvDriverNRIC2.Enabled = false;
        rfvDriverLicensePassDate2.Enabled = false;
        rfvDriverRelation2.Enabled = false;
        rfvDriverName3.Enabled = false;
        rfvDriverNRIC3.Enabled = false;
        rfvDriverLicensePassDate3.Enabled = false;
        rfvDriverRelation3.Enabled = false;
        rfvDriverName4.Enabled = false;
        rfvDriverNRIC4.Enabled = false;
        rfvDriverLicensePassDate4.Enabled = false;
        rfvDriverRelation4.Enabled = false;
        rfvDriverName5.Enabled = false;
        rfvDriverNRIC5.Enabled = false;
        rfvDriverLicensePassDate5.Enabled = false;
        rfvDriverRelation5.Enabled = false;
        if (OnOff == true)
        {
            if (NoofDriver > 0)
            {
                pnlDriver1.Visible = true;
                rfvDriverName1.Enabled = OnOff;
                rfvDriverNRIC1.Enabled = OnOff;
                rfvDriverLicensePassDate1.Enabled = OnOff;
                rfvDriverRelation1.Enabled = OnOff;
            }
            if (NoofDriver > 1)
            {
                pnlDriver2.Visible = true;
                rfvDriverName2.Enabled = OnOff;
                rfvDriverNRIC2.Enabled = OnOff;
                rfvDriverLicensePassDate2.Enabled = OnOff;
                rfvDriverRelation2.Enabled = OnOff;
            }
            if (NoofDriver > 2)
            {
                pnlDriver3.Visible = true;
                rfvDriverName3.Enabled = OnOff;
                rfvDriverNRIC3.Enabled = OnOff;
                rfvDriverLicensePassDate3.Enabled = OnOff;
                rfvDriverRelation3.Enabled = OnOff;
            }
            if (NoofDriver > 3)
            {
                pnlDriver4.Visible = true;
                rfvDriverName4.Enabled = OnOff;
                rfvDriverNRIC4.Enabled = OnOff;
                rfvDriverLicensePassDate4.Enabled = OnOff;
                rfvDriverRelation4.Enabled = OnOff;
            }
            if (NoofDriver > 4)
            {
                pnlDriver5.Visible = true;
                rfvDriverName5.Enabled = OnOff;
                rfvDriverNRIC5.Enabled = OnOff;
                rfvDriverLicensePassDate5.Enabled = OnOff;
                rfvDriverRelation5.Enabled = OnOff;
            }
        }
    }

    protected void btnDownload_Click(object sender, EventArgs e)
    {
        //Response.Redirect(hplDownLoad.NavigateUrl);
    }

    private void LoadCoverType()
    {
        ddlCoverType.Items.Clear();
        DataTable _dtCoverType = General.GetComboItem("ProviderCoverType", "CXBrokerProviderId", "0", true);
        if (_dtCoverType.Rows.Count > 0)
        {
            ddlCoverType.DataSource = _dtCoverType;
            ddlCoverType.DataTextField = _dtCoverType.Columns[0].ColumnName.ToString();
            ddlCoverType.DataValueField = _dtCoverType.Columns[1].ColumnName.ToString();
            ddlCoverType.DataBind();
        }
        ddlCoverType.Items.Insert(0, new ListItem("Select", "-1"));
    }

    protected void btnSubmitMore_Click(object sender, EventArgs e)
    {
        if (CheckValid())
        {
            int _insertcount = 0;
            int NoofDriver = Convert.ToInt32(txtNoofDriver.Text);
            if (NoofDriver <= 0)
            {
                _insertcount = 1;
            }
            CXCarMoreDetail _cxcarmoredetail = new CXCarMoreDetail();
            CXCarMoreDetailDB _cxcarmoredetaildb = new CXCarMoreDetailDB();
            _cxcarmoredetail.MoreDetailId = 0;
            _cxcarmoredetail.CECarId = Convert.ToInt64(txtCarId.Text);
            _cxcarmoredetail.RefCEUserId = Convert.ToInt64(txtCustomerId.Text);
            _cxcarmoredetail.AgentId = Convert.ToInt64(txtAgentId.Text);
            _cxcarmoredetail.NRIC = Server.HtmlEncode(txtNRIC.Text);
            _cxcarmoredetail.LicensePassDate = txtLicensePassDate.Text;
            _cxcarmoredetail.RegistrationDate = txtRegistrationDate.Text;
            _cxcarmoredetail.VehicleNumber = Server.HtmlEncode(txtVehicleNumber.Text);
            _cxcarmoredetail.CoverType = Convert.ToInt32(ddlCoverType.Text);
            _cxcarmoredetail.LicenseSuspension = ddlSuspensionDrivingLicense.Text;
            _cxcarmoredetail.PolicyCancelled = ddlPolicyCancelled.Text;
            _cxcarmoredetail.Status = true;
            _cxcarmoredetail.MoreDetailId = _cxcarmoredetaildb.Insert(_cxcarmoredetail);
            if (_cxcarmoredetail.MoreDetailId > 0)
            {
                CXCarDriverMoreDetail _cxcardrivermoredetail = new CXCarDriverMoreDetail();
                CXCarDriverMoreDetailDB _cxcardrivermoredetaildb = new CXCarDriverMoreDetailDB();

                _cxcardrivermoredetail.DriverDetailId = 0;
                _cxcardrivermoredetail.CECarId = Convert.ToInt64(txtCarId.Text);
                _cxcardrivermoredetail.RefCEUserId = Convert.ToInt64(txtCustomerId.Text);
                _cxcardrivermoredetail.AgentId = Convert.ToInt64(txtAgentId.Text);
                for (int i = 1; i <= NoofDriver; i++)
                {
                    if (i == 1)
                    {
                        _cxcardrivermoredetail.DriverId = Convert.ToInt64(txtDriverId1.Text);
                        _cxcardrivermoredetail.Name = Server.HtmlEncode(txtDriverName1.Text);
                        _cxcardrivermoredetail.NRIC = Server.HtmlEncode(txtDriverNRIC1.Text);
                        _cxcardrivermoredetail.LicensePassDate = txtDriverLicensePassDate1.Text;
                        _cxcardrivermoredetail.Relation = Server.HtmlEncode(txtDriverRelation1.Text);
                    }
                    else if (i == 2)
                    {
                        _cxcardrivermoredetail.DriverId = Convert.ToInt64(txtDriverId2.Text);
                        _cxcardrivermoredetail.Name = Server.HtmlEncode(txtDriverName2.Text);
                        _cxcardrivermoredetail.NRIC = Server.HtmlEncode(txtDriverNRIC2.Text);
                        _cxcardrivermoredetail.LicensePassDate = txtDriverLicensePassDate2.Text;
                        _cxcardrivermoredetail.Relation = Server.HtmlEncode(txtDriverRelation2.Text);
                    }
                    else if (i == 3)
                    {
                        _cxcardrivermoredetail.DriverId = Convert.ToInt64(txtDriverId3.Text);
                        _cxcardrivermoredetail.Name = Server.HtmlEncode(txtDriverName3.Text);
                        _cxcardrivermoredetail.NRIC = Server.HtmlEncode(txtDriverNRIC3.Text);
                        _cxcardrivermoredetail.LicensePassDate = txtDriverLicensePassDate3.Text;
                        _cxcardrivermoredetail.Relation = Server.HtmlEncode(txtDriverRelation3.Text);
                    }
                    else if (i == 4)
                    {
                        _cxcardrivermoredetail.DriverId = Convert.ToInt64(txtDriverId4.Text);
                        _cxcardrivermoredetail.Name = Server.HtmlEncode(txtDriverName4.Text);
                        _cxcardrivermoredetail.NRIC = Server.HtmlEncode(txtDriverNRIC4.Text);
                        _cxcardrivermoredetail.LicensePassDate = txtDriverLicensePassDate4.Text;
                        _cxcardrivermoredetail.Relation = Server.HtmlEncode(txtDriverRelation4.Text);
                    }
                    else if (i == 5)
                    {
                        _cxcardrivermoredetail.DriverId = Convert.ToInt64(txtDriverId5.Text);
                        _cxcardrivermoredetail.Name = Server.HtmlEncode(txtDriverName5.Text);
                        _cxcardrivermoredetail.NRIC = Server.HtmlEncode(txtDriverNRIC5.Text);
                        _cxcardrivermoredetail.LicensePassDate = txtDriverLicensePassDate5.Text;
                        _cxcardrivermoredetail.Relation = Server.HtmlEncode(txtDriverRelation5.Text);
                    }
                    _cxcardrivermoredetail.Status = true;
                    if (_cxcardrivermoredetaildb.Insert(_cxcardrivermoredetail) > 0)
                    {
                        _insertcount++;
                    }
                }
                if (_insertcount > 0)
                {
                    lblMoreDetailsMessage.Text = "Successfully Saved";
                    lblMoreDetailsError.Text = "";
                    hplDownLoad.Visible = true;
                    divCustomerMoreDetail.Visible = false;
                    btnSubmitPremium.Enabled = true;
                    hplDownLoad.NavigateUrl = "~/CarInsurance/QuoteDownload.aspx?carid=" + txtCarId.Text + "&userid=" + txtCustomerId.Text;
                }
                else
                {
                    lblMoreDetailsMessage.Text = "";
                    lblMoreDetailsError.Text = "Faild";
                    hplDownLoad.Visible = false;
                    btnSubmitPremium.Enabled = false;
                }
            }
            else
            {
                lblMoreDetailsMessage.Text = "";
                lblMoreDetailsError.Text = "Faild";
                hplDownLoad.Visible = false;
                btnSubmitPremium.Enabled = false;
            }
        }
    }

    private bool CheckValid()
    {
        bool _Isvalid = true;
        if (rfvLicensePassDate.Enabled == true)
        {
            if (rfvLicensePassDate.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvRegistrationDate.Enabled == true)
        {
            if (rfvRegistrationDate.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvVehicleNumber.Enabled == true)
        {
            if (rfvVehicleNumber.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvCoverType.Enabled == true)
        {
            if (rfvCoverType.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvNRIC.Enabled == true)
        {
            if (rfvNRIC.IsValid == false)
            {
                _Isvalid = false;
            }
        };
        if (rfvSuspensionDrivingLicense.Enabled == true)
        {
            if (rfvSuspensionDrivingLicense.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvPolicyCancelled.Enabled == true)
        {
            if (rfvPolicyCancelled.IsValid == false)
            {
                _Isvalid = false;
            }
        }

        //Drivers
        if (rfvDriverName1.Enabled == true)
        {
            if (rfvDriverName1.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverNRIC1.Enabled == true)
        {
            if (rfvDriverNRIC1.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverLicensePassDate1.Enabled == true)
        {
            if (rfvDriverLicensePassDate1.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverRelation1.Enabled == true)
        {
            if (rfvDriverRelation1.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverName2.Enabled == true)
        {
            if (rfvDriverName2.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverNRIC2.Enabled == true)
        {
            if (rfvDriverNRIC2.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverLicensePassDate2.Enabled == true)
        {
            if (rfvDriverLicensePassDate2.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverRelation2.Enabled == true)
        {
            if (rfvDriverRelation2.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverName3.Enabled == true)
        {
            if (rfvDriverName3.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverNRIC3.Enabled == true)
        {
            if (rfvRegistrationDate.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverLicensePassDate3.Enabled == true)
        {
            if (rfvDriverLicensePassDate3.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverRelation3.Enabled == true)
        {
            if (rfvDriverRelation3.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverName4.Enabled == true)
        {
            if (rfvDriverName4.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverNRIC4.Enabled == true)
        {
            if (rfvDriverNRIC4.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverLicensePassDate4.Enabled == true)
        {
            if (rfvDriverLicensePassDate4.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverRelation4.Enabled == true)
        {
            if (rfvDriverRelation4.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverName5.Enabled == true)
        {
            if (rfvDriverName5.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverNRIC5.Enabled == true)
        {
            if (rfvDriverNRIC5.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverLicensePassDate5.Enabled == true)
        {
            if (rfvDriverLicensePassDate5.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        if (rfvDriverRelation5.Enabled == true)
        {
            if (rfvDriverRelation5.IsValid == false)
            {
                _Isvalid = false;
            }
        }
        return _Isvalid;
    }

    protected void ddlBrokerProvider_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblPremiumError.Text = "";
        lblPremiumMessage.Text = "";
        LoadBrokerCoverType();
    }

    protected void ddlBrokerCoverType_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblPremiumError.Text = "";
        lblPremiumMessage.Text = "";
        BrokerPremium _brokerPremium = new BrokerPremium();
        BrokerPremiumDB _brokerPremiumdb = new BrokerPremiumDB();
        if (ddlBrokerCoverType.SelectedIndex > 0)
        {
            Int64 _CXBrokerId = Convert.ToInt64(ddlBrokerProvider.Text);
            Int64 _CXCoverTypeId = Convert.ToInt64(ddlBrokerCoverType.Text);
            Int64 _CECarId = Convert.ToInt64(txtCarId.Text);
            Int64 _CustomerId = Convert.ToInt64(txtCustomerId.Text);

            _brokerPremium = _brokerPremiumdb.GetBrokerPremium(_CXBrokerId, _CXCoverTypeId, _CECarId, _CustomerId);
            if (_brokerPremium != null)
            {
                txtPremiumId.Text = _brokerPremium.CXBrokerPremiumId.ToString();
                txtPremium.Text = _brokerPremium.Premium.ToString();
                txtExcess.Text = _brokerPremium.Excess.ToString();
                chkSelected.Checked = _brokerPremium.SelectedStatus;
                txtPremiumPackage.Text = _brokerPremium.Package;
                txtWorkShop.Text = _brokerPremium.WorkShop;
            }
            else
            {
                txtPremiumId.Text = "0";
                txtPremium.Text = "";
                txtExcess.Text = "";
                txtPremiumPackage.Text = "";
                txtWorkShop.Text = "";
                chkSelected.Checked = false;
            }
        }
        else
        {
            txtPremiumId.Text = "0";
            txtPremium.Text = "";
            txtExcess.Text = "";
            txtPremiumPackage.Text = "";
            txtWorkShop.Text = "";
            chkSelected.Checked = false;
        }
        _brokerPremium = null;
        _brokerPremiumdb = null;
    }

    private void LoadBrokerProvider()
    {
        lblPremiumError.Text = "";
        lblPremiumMessage.Text = "";
        DataTable _dtBrokerProvider = General.GetComboItem("BrokerProvider", true);
        ddlBrokerProvider.DataSource = _dtBrokerProvider;
        ddlBrokerProvider.DataTextField = _dtBrokerProvider.Columns[0].ColumnName.ToString();
        ddlBrokerProvider.DataValueField = _dtBrokerProvider.Columns[1].ColumnName.ToString();
        ddlBrokerProvider.DataBind();

        ddlBrokerProvider.Items.Insert(0, new ListItem("Select", "-1"));
    }

    private void LoadBrokerCoverType()
    {
        lblPremiumError.Text = "";
        lblPremiumMessage.Text = "";
        ddlBrokerCoverType.Items.Clear();
        DataTable _dtBrokerCoverType = General.GetComboItem("ProviderCoverType", "CXBrokerProviderId", "0", true);
        if (_dtBrokerCoverType.Rows.Count > 0)
        {
            ddlBrokerCoverType.DataSource = _dtBrokerCoverType;
            ddlBrokerCoverType.DataTextField = _dtBrokerCoverType.Columns[0].ColumnName.ToString();
            ddlBrokerCoverType.DataValueField = _dtBrokerCoverType.Columns[1].ColumnName.ToString();
            ddlBrokerCoverType.DataBind();
        }
        ddlBrokerCoverType.Items.Insert(0, new ListItem("Select", "-1"));
        txtPremiumId.Text = "0";
        txtPremium.Text = "";
        txtExcess.Text = "";
        txtPremiumPackage.Text = "";
        txtWorkShop.Text = "";
        chkSelected.Checked = false;
    }

    protected void btnSubmitPremium_Click(object sender, EventArgs e)
    {
        Page.Validate("premium");
        if (IsValid)
        {
            if (txtExcess.Text.Trim() == "")
            {
                txtExcess.Text = "0";
            }
            Int64 _result = 0;
            BrokerPremium _brokerPremium = new BrokerPremium();
            BrokerPremiumDB _brokerPremiumdb = new BrokerPremiumDB();

            txtPremiumPackage.Text = Server.HtmlEncode(txtPremiumPackage.Text);
            txtWorkShop.Text = Server.HtmlEncode(txtWorkShop.Text);

            _brokerPremium.CXBrokerPremiumId = Convert.ToInt64(txtPremiumId.Text);
            _brokerPremium.CXBrokerProviderId = Convert.ToInt64(ddlBrokerProvider.Text);
            _brokerPremium.ProviderCoverTypeId = Convert.ToInt64(ddlBrokerCoverType.Text);
            _brokerPremium.CECarId = Convert.ToInt64(txtCarId.Text);
            _brokerPremium.CustomerId = Convert.ToInt64(txtCustomerId.Text);
            _brokerPremium.AgentId = Convert.ToInt64(txtAgentId.Text);
            _brokerPremium.Premium = Convert.ToSingle(txtPremium.Text);
            _brokerPremium.Excess = Convert.ToSingle(txtExcess.Text);
            _brokerPremium.SelectedStatus = chkSelected.Checked;
            _brokerPremium.Package = txtPremiumPackage.Text;
            _brokerPremium.WorkShop = txtWorkShop.Text;
            _brokerPremium.ProductType = "CRM";

            _result = _brokerPremiumdb.Insert(_brokerPremium);
            if (_result > 0)
            {
                txtPremiumId.Text = _result.ToString();
                lblPremiumError.Text = "";
                lblPremiumMessage.Text = "Successfully Updated";

                grvPremiumList.DataBind();
                if (grvPremiumList.Rows.Count > 0)
                {
                    divPremiumList.Visible = true;
                    hplPremiumDownLoad.Visible = true;
                    hplPremiumDownLoad.NavigateUrl = PremiumDownloadURL();
                }
                else
                {
                    divPremiumList.Visible = false;
                    hplPremiumDownLoad.Visible = false;
                    hplPremiumDownLoad.NavigateUrl = "";
                }
                //hplPremiumDownLoad.NavigateUrl = PremiumDownloadURL();
            }
            else
            {
                txtPremiumId.Text = "0";
                lblPremiumError.Text = "Updated Failed";
                lblPremiumMessage.Text = "";
            }
        }
    }

    protected void grvPremiumList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Delete"))
        {
            if (e.CommandArgument != null)
            {
                Int64 _AgentId = 0;
                Int64 _CXBrokerPremiumId = 0;
                _CXBrokerPremiumId = Convert.ToInt64(e.CommandArgument);
                _AgentId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                sqlDsPremiumList.DeleteParameters["CXBrokerPremiumId"].DefaultValue = _CXBrokerPremiumId.ToString();
                sqlDsPremiumList.DeleteParameters["AgentId"].DefaultValue = _AgentId.ToString();
                sqlDsPremiumList.Delete();
                grvPremiumList.DataBind();
                if (grvPremiumList.Rows.Count > 0)
                {
                    hplPremiumDownLoad.Visible = true;
                }
                else
                {
                    hplPremiumDownLoad.Visible = false;
                }
                lblPremiumError.Text = "";
                lblPremiumMessage.Text = "";
                txtPremiumId.Text = "0";
                txtPremium.Text = "";
                txtExcess.Text = "";
                txtPremiumPackage.Text = "";
                txtWorkShop.Text = "";
                chkSelected.Checked = false;
                ddlBrokerProvider.SelectedIndex = 0;
                ddlBrokerCoverType.SelectedIndex = 0;
            }
        }
    }

    protected void btnPremiumDownload_Click(object sender, EventArgs e)
    {
        if (grvPremiumList.Rows.Count > 0)
        {
            string VehicleNo = "";
            DataTable _dtSelect = new DataTable();
            MyDatabase _db = new MyDatabase();
            Int64 CECarId = Convert.ToInt64(txtCarId.Text);
            string _strSelect = "SELECT VehicleNumber FROM tblCXCarMoreDetail WHERE CECarId = " + txtCarId.Text + " AND RefCEUserId =" + txtCustomerId.Text + " AND [Status] = 1";
            _strSelect += " AND RefCEUserId = " + txtCustomerId.Text;
            _dtSelect = _db.GetDataTable(_strSelect);
            if (_dtSelect != null && _dtSelect.Rows.Count > 0)
            {
                VehicleNo = _dtSelect.Rows[0]["VehicleNumber"].ToString();
            }
            SetPremiumDownLoadLink(txtCarId.Text, VehicleNo);
        }
    }

    public void SetPremiumDownLoadLink(string CarId, string VehicleNo)
    {
        string url = "PremiumDownload.aspx?carid=" + CarId.ToString() + "," + VehicleNo.ToString();

        StringBuilder sb = new StringBuilder();
        sb.Append("<script>");
        sb.Append("window.open('" + url + "', '', '');");
        sb.Append("</scri");
        sb.Append("pt>");
        ClientScript.RegisterStartupScript(GetType(), "test", sb.ToString());

    }

    public string PremiumDownloadURL()
    {
        string url = "~/carinsurance/PremiumDownload.aspx?carid=" + txtCarId.Text + "," + txtCustomerId.Text + ",";
        string VehicleNo = "SSS 0000 A";
        DataTable _dtSelect = new DataTable();
        MyDatabase _db = new MyDatabase();
        Int64 CECarId = Convert.ToInt64(txtCarId.Text);
        string _strSelect = "SELECT VehicleNumber FROM tblCXCarMoreDetail WHERE CECarId = " + txtCarId.Text + " AND RefCEUserId =" + txtCustomerId.Text + " AND [Status] = 1";
        _strSelect += " AND RefCEUserId = " + txtCustomerId.Text;
        _dtSelect = _db.GetDataTable(_strSelect);
        if (_dtSelect != null && _dtSelect.Rows.Count > 0)
        {
            VehicleNo = _dtSelect.Rows[0]["VehicleNumber"].ToString();
        }
        url += VehicleNo;
        return url;
    }

    protected void btnBrokerCallStatus_Click(object sender, EventArgs e)
    {
        lblBrokerCallStatusMessage.Text = "";
        Page.Validate("brokercallstatus");
        if (Page.IsValid)
        {
            if (txtCarId.Text.Length > 0 && txtCustomerId.Text.Length > 0)
            {
                BrokerCallStatus brokercallstatus = new BrokerCallStatus();
                BrokerCallStatusDB brokercallstatusdb = new BrokerCallStatusDB();
                if (txtBrokerCallStatusId.Text.Length > 0 && txtBrokerCallStatusId.Text != "0")
                {
                    brokercallstatus.CallStatusId = Convert.ToInt64(txtBrokerCallStatusId.Text);
                }
                else
                {
                    brokercallstatus.CallStatusId = 0;
                }
                brokercallstatus.CECarId = Convert.ToInt64(txtCarId.Text);
                brokercallstatus.CustomerId = Convert.ToInt64(txtCustomerId.Text);
                brokercallstatus.AgentId = Convert.ToInt64(txtAgentId.Text);
                brokercallstatus.AgentCallStatus = Convert.ToInt32(ddlBrokerCallStatus.Text);
                brokercallstatus.CallTypeId = 192;
                brokercallstatus.Remark = Server.HtmlEncode(txtBrokerRemark.Text);
                brokercallstatus.CallStatusId = brokercallstatusdb.Insert(brokercallstatus);
                if (brokercallstatus.CallStatusId > 0)
                {
                    if (txtBrokerCallStatusId.Text.Length > 0 && txtBrokerCallStatusId.Text != "0")
                    {
                        lblBrokerCallStatusMessage.Text = "UPDATE";
                    }
                    else
                    {
                        txtBrokerCallStatusId.Text = brokercallstatus.CallStatusId.ToString();
                        lblBrokerCallStatusMessage.Text = "SUCCESS";
                    }
                }
                else
                {
                    lblBrokerCallStatusMessage.Text = "FAIL";
                }
                brokercallstatus = null;
                brokercallstatusdb = null;
            }
            else
            {
                lblBrokerCallStatusMessage.Text = "FAIL";
            }
        }
    }

}
